<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_traceAnalyst"></title>
    <style>
      #toolbar {
         position: absolute;
         top: 50px;
         right: 10px;
         width: 280px;
         text-align: center;
         z-index: 999;
         border-radius: 4px;
       }
    </style>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
<div id="toolbar" class="panel panel-primary">
  <div class='panel-heading'>
      <h5 class='panel-title text-center' data-i18n="resources.text_traceAnalyst"></h5></div>
  <div class='panel-body content'>
      <div class='panel'>
        <div class='input-group'>
            <span class='input-group-addon' data-i18n="resources.text_traceType"></span>
            <select id='traceType' class='form-control'>
              <option value=0 data-i18n="resources.text_traceUp"></option>
              <option value=1 data-i18n="resources.text_traceDown"></option>
            </select>
          </div>
      </div>
      <div class='panel'>
        <div class='input-group'>
            <span class='input-group-addon' data-i18n="resources.text_isUncertainDirectionValid"></span>
            <select id='isUncertainDirectionValid' class='form-control'>
              <option value=0>false</option>
              <option value=1 selected>true</option>
            </select>
          </div>
      </div>
      <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_traceAnalyst"
              onclick="traceAnalystProcess()"/>&nbsp;
      <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_clearLayer"
              onclick="removeLayer()"/>
  </div>
</div>
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var map, resultLayer,
        baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
        serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
    map = L.map('map', {
      crs: new L.supermap.CRS.NonEarthCRS({
        bounds: L.bounds([48.4, -7668.25], [8958.85, -55.58]),
        origin: L.point(48.4, -55.58)
      }),
      center: [-3861.91, 4503.62],
      maxZoom: 18,
      zoom: 2
    });
    new L.supermap.TiledMapLayer(baseUrl, {noWrap: true})
        .addTo(map)
        .on('load', function () {
            addLayer();
        });

    function addLayer() { 
        // 添加需查找上/下游设施的要素
        var param = new L.supermap.QueryBySQLParameters({
            queryParams: {
                name: "RoadNet@Changchun",
                attributeFilter: "SMID = 101"
            }
        });
        new L.supermap.QueryService(baseUrl).queryBySQL(param).then(function (serviceResult) {
          var resultFeatures = serviceResult.result.recordsets[0].features;
          vectorLayer = L.geoJSON(resultFeatures,{
            style: function (feature) {
                return {
                  color: 'red', // 线的颜色
                  weight: 5, // 线的宽度
                };
              }
            }).addTo(map);
        });
    }
   

    function traceAnalystProcess() {
        removeLayer();
        var traceType = +document.getElementById("traceType").value;
        var isUncertainDirectionValid = document.getElementById("isUncertainDirectionValid").value === "0" ? false : true;
        var traceAnalystParameters = new L.supermap.TraceAnalystParameters({
            edgeID:101,
            traceType:traceType,
            weightName:"",
            isUncertainDirectionValid: isUncertainDirectionValid,
            returnFeatures: true
        });
        //进行查找
        new L.supermap.NetworkAnalystService(serviceUrl).traceAnalyst(traceAnalystParameters).then(function (serviceResult) {
            resultLayer = L.geoJSON(serviceResult.result.edgesFeatures).addTo(map);
        });
    }
    //移除结果图层
    function removeLayer() {
      if (resultLayer && map.hasLayer(resultLayer)) {
        map.removeLayer(resultLayer);
      }
    }
</script>
</body>
</html>